package com.tt.service.impl;

import com.tt.mapper.CourseMapper;
import com.tt.pojo.Course;
import com.tt.service.CourseService;
import com.tt.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper mapper;
    @Override
    public PageResult getCourseList(PageResult pageResult) {
        long total = mapper.findTotal();
        //分页的结果
        int size = pageResult.getPageSize();//条数
        int start = (pageResult.getPageNum()-1) * size;//起始位置
        String name = pageResult.getName();//查询条件
        List<Course> courseList = mapper.findCourseByPage(start,size,name);
        return pageResult.setTotal(total).setRows(courseList);
    }

    @Override
    @Transactional
    public void addCourse(Course course) {
        mapper.insert(course);
    }

    @Override
    @Transactional
    public void deleteCourseById(Long id) {
        mapper.deleteById(id);
    }

    @Override
    @Transactional
    public void updateCourseById(Course course) {
        mapper.updateById(course);
    }

}
